package leetcode.editor.cn;

import java.util.Arrays;

//Java：盛最多水的容器
public class ContainerWithMostWater {
    public static void main(String[] args) {
        Solution solution = new ContainerWithMostWater().new Solution();
        // TO TEST
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int maxArea(int[] height) {
            //1、声明三个必须的变量：面积、左指针、右指针。
            int maxArea = 0;
            int left = 0;
            int right = height.length - 1;
            //2、循环遍历找出最大面积
            while (left < right) {
                //2.1、计算面积并返回当前面积和上次计算的值作比较，返回最大值
                maxArea = Math.max(maxArea, Math.min(height[left], height[right]) * (right - left));
                //2.2、排除值较小的指针
                if (height[left] < height[right]) {
                    left++;
                } else {
                    right--;
                }
            }
            //3、返回面积值
            return maxArea;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}